export default {
	getUserInfo() {
		const db = this.database();
		const userCol = db.collection('user');
		return userCol.get();
	},

	async addUser({ data }) {
		const db = this.database();
		const userCol = db.collection('user');

		const res = await userCol.where({
			telephone: data.telephone,
		}).get()

		if (res.data.length === 0 && data && data.telephone.length > 0 && data.password.length > 0) {
			const userInfo = {
				nickName: '',
				telephone: data.telephone,
				password: data.password,
				createTimeStamp: new Date().getTime(),
				birthday: '2021-01-01',
				credentialNo: '',
				deviceList: [],
			};
			wf.getModule('reporter').report('custom', 'addUser', {
				userInfo,
			});
			return userCol.add(userInfo);
		}
		return Promise.reject({});
	},

	async userLogin({ data }) {
		const db = this.database();
		const userCol = db.collection('user');
		const { telephone, password } = data;
		const res = await userCol.where({
			telephone,
			password,
		}).get()

		console.log(res, data);

		if (res.data.length > 0) {
			return res.data[0]
		}


		// if (res.data.length === 0 && data && data.telephone.length > 0 && data.password.length > 0) {
		// 	const userInfo = {
		// 		nickName: '',
		// 		telephone: data.telephone,
		// 		password: data.password,
		// 		createTimeStamp: new Date().getTime(),
		// 		birthday: '2021-01-01',
		// 		credentialNo: '',
		// 		deviceList: [],
		// 	};
		// 	wf.getModule('reporter').report('custom', 'addUser', {
		// 		userInfo,
		// 	});
		// 	return userCol.add(userInfo);
		// }

		return Promise.reject({
			message: "未找到该用户"
		});
	}
};
